package com.spring.lth.controller;

import com.spring.lth.domain.Person;
import com.spring.lth.domain.PersonAndCard;
import com.spring.lth.service.IPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * @author 罗天豪
 * @date 2019/7/26
 */
@RestController
@RefreshScope
public class PersonController {

    @Autowired
    private IPersonService service;

    @Value("${server.time}")
    String testValue;

    @GetMapping("/person/{id}")
    public PersonAndCard getPersonById(@PathVariable Long id) {
        PersonAndCard personById = service.getPersonById(id);
        return personById;
    }

    @GetMapping("/getTestValue")
    public String getTestValue(){
        return testValue;
    }

    @PostMapping("/person")
    public PersonAndCard savePerson(@RequestBody Person person) {
        PersonAndCard personAndCard = service.savePerson(person);
        return personAndCard;
    }

    @DeleteMapping("/person")
    public PersonAndCard removePerson(@RequestBody Person person) {
        PersonAndCard personAndCard = service.removePerson(person);
        return personAndCard;
    }
}
